﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using Htss.Platform.Web;
using Htss.Platform.Core;

namespace DreamBox.Web.Box.user
{
    public class passwordBox:ControllerBox
    {
        public ActionResult Load()
        {
            if (Request.RequestType == "POST")
            {
                if (Verification())
                {
                    DAL.User.UserInfo user = new DAL.User.UserInfo();
                    if (user.UpdatePassword(int.Parse(Session["UserID"].ToString()), FormsAuthentication.HashPasswordForStoringInConfigFile(Request.Form["Password"], "MD5")))
                    {
                        BLL.Message.Jump(this, "密码修改成功", "/user/info", "1");
                    }
                }
            }
            return View("user_password");
        }
        bool Verification()
        {

            Verify vf = new Verify();
            vf.VerificationMessage = VerificationMessage;
            VerifyField vPassword = vf.NewVerifyField(Request.Form["Password"], "Password");
            vPassword.AddNull("此项不能为空");
            vPassword.AddLengthRange("请输入(6-20)之间的密码长度", 6, 20);

            VerifyField vConfirmPassword = vf.NewVerifyField(Request.Form["ConfirmPassword"], "ConfirmPassword");
            vConfirmPassword.AddNull("此项不能为空");
            vConfirmPassword.AddLengthRange("请输入(6-20)之间的密码长度", 6, 20);
            vConfirmPassword.AddCompare("请输入两次相同的密码", Request.Form["Password"]);

            vf.Begin();
            return vf.IsVerify;
        }
    }
}
